package com.light.gamecomponents;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer;

public class CullingSprite extends Sprite
{
	final static int PADDING = 100;
	public CullingSprite(final float pX, final float pY, final TextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion);
	}

	public CullingSprite(final float pX, final float pY, final float pWidth, final float pHeight, final TextureRegion pTextureRegion) {
		super(pX, pY, pWidth, pHeight, pTextureRegion);
	}

	public CullingSprite(final float pX, final float pY, final TextureRegion pTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) {
		super(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pRectangleVertexBuffer);
	}

	public CullingSprite(final float pX, final float pY, final float pWidth, final float pHeight, final TextureRegion pTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) {
		super(pX, pY, pWidth, pHeight, pTextureRegion, pRectangleVertexBuffer);
	}
	
	protected void onManagedDraw(final GL10 pGL, final Camera pCamera)
	{
		if(!(this.mX > pCamera.getCenterX() + pCamera.getWidth() / 2 + PADDING ||
			this.mX + this.mWidth < pCamera.getCenterX() - pCamera.getWidth() / 2 - PADDING ||
			this.mY > pCamera.getCenterY() + pCamera.getHeight() / 2 + PADDING ||
			this.mY + this.mHeight < pCamera.getCenterY() - pCamera.getHeight() / 2 - PADDING))
		{
			super.onManagedDraw(pGL, pCamera);
		}
	}
}

